package com.chencs.webmvc.rest;

import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.client.SimpleClientHttpRequestFactory;
import org.springframework.web.client.RestTemplate;

@Configuration
public class RestConfigure {



	/**
     * 实例化RestTemplate，通过@LoadBalanced注解开启均衡负载能力.
     * @return restTemplate
     */
	@Bean
	@LoadBalanced
	public RestTemplate nativeRestTemplate(){
		return new RestTemplate(httpClientFactory());
	}
	@Bean
	public SimpleClientHttpRequestFactory httpClientFactory(){
		SimpleClientHttpRequestFactory schrf = new SimpleClientHttpRequestFactory();
		schrf.setConnectTimeout(5000);
		schrf.setReadTimeout(60000);
		return schrf;
	}
}
